/*
 * Copyright (c) 2024 iSOFT INFRASTRUCTURE SOFTWARE CO., LTD.
 * easyAda is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */

#ifndef __DEVICE_H__
#define __DEVICE_H__

#include <plat/config.h>
#include <stdlib/stddef.h>
#include <stdlib/stdint.h>
#include <stdlib/string.h>
#include <tools/list.h>

#define DEV_MAX_NAME     256
#define device_name(dev) dev->name
extern list_t dev_list;

typedef struct {
    char   name[DEV_MAX_NAME];
    list_t list;
} device_t;

typedef struct {
    uint32_t is_sd;
    device_t blk_dev;
} blk_device_t;

static inline device_t *find_dev(const char *name)
{
    device_t *dev;

    list_foreach(dev, &dev_list, device_t, list)
    {
        if (0 == strncmp(device_name(dev), name, DEV_MAX_NAME)) {
            return dev;
        }
    }
    return NULL;
}

#define DEVICE_PBASE_UART 0xfe210000

#ifndef MMU_ENABLE
#define DEVICE_VBASE_UART DEVICE_PBASE_UART
#else
#define DEVICE_VBASE_UART (CONFIG_KDEV_ADDR + 0)
#endif
#define DEVICE_SIZE_UART (64 * 1024)

#define DEVICE_PBASE_GIC 0xff840000
#ifdef MMU_ENABLE
#define DEVICE_VBASE_GIC (DEVICE_VBASE_UART + DEVICE_SIZE_UART)
#else
#define DEVICE_VBASE_GIC DEVICE_PBASE_GIC
#endif
#define DEVICE_SIZE_GIC   (64 * 1024)
#define DEVICE_SIZE_RES   (4 * 1024)
#define DEVICE_SIZE_GICD  (4 * 1024)
#define DEVICE_SIZE_GICC  (4 * 1024)
#define DEVICE_VBASE_GICD (DEVICE_VBASE_GIC + DEVICE_SIZE_RES)
#define DEVICE_VBASE_GICC (DEVICE_VBASE_GICD + DEVICE_SIZE_GICD)

#define    IRQN_TIMER0  30
#define    IRQN_UART  125

#endif
